/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "WaterEffectManager.h"

#include "Hydrax.h"
#include "Noise/Perlin/Perlin.h"
#include "Modules/ProjectedGrid/ProjectedGrid.h"

namespace Fish3D
{
	// Hydrax pointer,here for i don't want to expose the implement
	Hydrax::Hydrax *__hydrax = 0;

	WaterEffectManager::WaterEffectManager(Ogre::SceneManager* sceneMgr)
	{
		Ogre::Camera* cam=sceneMgr->getCamera(CameraNames::Normal);
		
		 // Create Hydrax object
		__hydrax = new Hydrax::Hydrax(sceneMgr, cam, cam->getViewport());

		Hydrax::Module::ProjectedGrid::Options ops;//(128,25,50,false,false,false,3.75f);
		// Create our projected grid module  
		Hydrax::Module::ProjectedGrid *mModule 
			= new Hydrax::Module::ProjectedGrid(// Hydrax parent pointer
												__hydrax,
												// Noise module
												new Hydrax::Noise::Perlin(/*Generic one*/),
												// Base plane
												Ogre::Plane(Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0)),
												// Normal mode
												Hydrax::MaterialManager::NM_RTT,
												// Projected grid options
												ops);

		// Set our module
		__hydrax->setModule(static_cast<Hydrax::Module::Module*>(mModule));

		// Load all parameters from config file
		// Remarks: The config file must be in Hydrax resource group.
		// All parameters can be set/updated directly by code(Like previous versions),
		// but due to the high number of customizable parameters, since 0.4 version, Hydrax allows save/load config files.
		__hydrax->loadCfg("fish3dwater0.hdx");

		// Create water
		__hydrax->create();

		__hydrax->getMaterialManager()->addDepthTechnique(static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("Island"))->createTechnique());
		
	}

	void WaterEffectManager::update(float deltaT)
	{
		__hydrax->update(deltaT);
	}

}
